package br.com.pucrs.tcc.bd;

import java.util.ArrayList;

import org.hibernate.Criteria;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import br.com.pucrs.tcc.ed.AreaInteresse;
import br.com.pucrs.tcc.ed.Professor;
import br.com.pucrs.tcc.ed.ProfessorAreaInteresse;
import br.com.pucrs.tcc.ed.Telefone;

public class ProfessorAreaInteresseBD {

	private Session mSession;

	public ProfessorAreaInteresseBD(Session session) {
		mSession = session;
	}

	public void insert(ProfessorAreaInteresse professorArea) {
		mSession.save(professorArea);
		mSession.flush();
	}

	public void update(ProfessorAreaInteresse professorArea) {
		mSession.update(professorArea);
	}

	public void delete(ProfessorAreaInteresse professorArea) {
		mSession.delete(professorArea);
		mSession.flush();
	}

	public Professor retrieve(ProfessorAreaInteresse professorArea) {
		Professor professorAreaRetorno = null;

		Criteria criteria = mSession.createCriteria(ProfessorAreaInteresse.class);
		//criteria.add(Restrictions.eq("id", grupo.getId()));

		professorAreaRetorno = (Professor) criteria.uniqueResult();

		return professorAreaRetorno;
	}

	public ArrayList<ProfessorAreaInteresse> list(ProfessorAreaInteresse professorArea) {
		ArrayList<ProfessorAreaInteresse> listaRetorno = null;

		Criteria criteria = mSession.createCriteria(ProfessorAreaInteresse.class);
		// criteria.add(Restrictions.eq("matricula", professor.getMatricula()));

		listaRetorno = (ArrayList<ProfessorAreaInteresse>) criteria.list();

		return listaRetorno;
	}
	
	public void deletePorProfessor(Professor professor) {
		StringBuilder sql = new StringBuilder();
		sql.append("DELETE FROM professores_areas_interesse ");
		sql.append(" WHERE professores_matricula = ? ");

		SQLQuery query = mSession.createSQLQuery(sql.toString());
		query.setString(0, professor.getMatricula());

		query.executeUpdate();
		
	}


}
